/*
 * @Author: your name
 * @Date: 2021-10-19 16:29:50
 * @LastEditTime: 2021-10-26 13:34:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \wx-x-mai\pages\workService\gxuniversity\firstpage\index.js
 */
/**
 * @see
 */
const app = getApp()
import {
  CounterClockwiseContourIntegral
} from '../../../../towxml/parse/parse2/entities/maps/entities'
import {
  getXnxqListGxdx
} from '../../../../utils/util'


const xnxqList = getXnxqListGxdx()
Page({
  data: {
    index: xnxqList.length - 1,
    xnxqList,
    imageUrl: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/bg.png',
    Image: 'https://xwx.gzzmedu.com:6899/wx-x-mai/gxImages/dialogbg.png',
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    check: "../../../../assets/images/check_2.png",
    checked: "../../../../assets/images/check_1.png",
    content: "adadadadadadadad",
    shows: true,
    xnxqListdata: xnxqList,
    indicatorDots: true,
    vertical: false,
    autoplay: false,
    interval: 2000,
    duration: 500,
    classId: "", //查询角色id参数
    currentIndex: "",
    currentIndexstu: "",
    currentIndexstucurr: [],
    roleList: [], //班主任角色
    classList: [], //学生角色
    classListdata: [],
    // array: ['美国', '中国', '巴西', '日本'],
    index: 0,
    beginSchoolYear: "", //开始
    endSchoolYear: "", //结束
    identityType: "", //区别学生和教师身份跳转不同页面

  },
  onLoad() {
    const userInfo = wx.getStorageSync('userInfo')

    this.setData({
      identityType: userInfo.identityType,
      beginSchoolYear: this.data.xnxqList[0].text,
      endSchoolYear: this.data.xnxqListdata[3].text
    })
    if (this.data.identityType == 4) {
      this.reportTerminfo();
    }
  },
  bindPickerChangedata: function (e) {
    this.setData({
      index: e.detail.value,
      currentIndex: this.data.roleList[e.detail.value],
      currentName: this.data.roleList[e.detail.value],
    })

  },

  bindPickerChangestu(e) {
    this.setData({
      classId: this.data.classList[e.detail.value].CLASSID,
      currentIndexstu: this.data.classList[e.detail.value].CLASSNAME
    })
  },
  reportTerminfo() {
    const request = {

    }
    wx.showLoading({
      title: '加载中',
    })
    wx.$API['workService/reportTerminfo'](request).then((result) => {
      wx.stopPullDownRefresh()
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)

      const {
        data
      } = result;
      // data.classListdata = data.classListdata.map((item) => item.CLASSNAME);
      // classListdata
      this.setData({
        roleList: data.roleList,
        classList: data.classList,
        currentIndex: data.roleList[0],
        currentIndexstu: data.classList[0].CLASSNAME,
        currentIndexstucurr: data.classList
      })

      const currentIndexstucurr = this.data.currentIndexstucurr.map((item) => item.CLASSNAME)
      this.setData({
        currentIndexstucurr: currentIndexstucurr
      })
    }).catch((error) => {
      wx.stopPullDownRefresh()
      wx.showToast({
        title: error,
        icon: 'error',
        duration: 1200
      })
      setTimeout(function () {
        wx.hideLoading()
      }, 1000)
    })
  },
  changeIndicatorDots(e) {
    console.log(e.detail.current)
    // this.setData({
    //   indicatorDots: !this.data.indicatorDots
    // })
  },
  bindPickerChange(e) {
    this.setData({
      beginSchoolYear: xnxqList[e.detail.value].id,
    })
    const request = {
      beginSchoolYear: this.data.beginSchoolYear
    }
    console.log(request.beginSchoolYear, '开始')
  },

  bindPickerChangebegin(e) {
    this.setData({
      endSchoolYear: xnxqList[e.detail.value].id,
    })
    const request = {
      endSchoolYear: this.data.endSchoolYear
    }
    console.log(request.endSchoolYear, '结束')
  },

  sueeess: function () {
    const beginSchoolYear = this.data.beginSchoolYear;
    const endSchoolYear = this.data.endSchoolYear;

    if (this.data.shows == false) {
      if (beginSchoolYear == '2018-2019第一学期') {
        this.setData({
          beginSchoolYear: "2018-2019-1"
        })
      }
      if (endSchoolYear == '2019-2020第一学期') {
        this.setData({
          endSchoolYear: "2019-2020-1"
        })
      }
      if (this.data.identityType == 1) { //等于1为学生
        wx.navigateTo({
          url: '../twopage/index?beginSchoolYear=' + this.data.beginSchoolYear + '&endSchoolYear=' + this.data.endSchoolYear,
        })
      }
      if (this.data.identityType == 4) { //等于4为教师
        this.data.classList.forEach(v => {
          if (v.CLASSNAME == this.data.currentIndexstu) {
            this.setData({
              classId: v.CLASSID
            })
          }
        });
        if (this.data.currentIndex != '班主任') {
          wx.navigateTo({
            url: '../teachermanage/teacher/index?beginSchoolYear=' + this.data.beginSchoolYear + '&endSchoolYear=' + this.data.endSchoolYear
          })
        } else {
          wx.navigateTo({
            url: '../teachermanage/teacher/index?beginSchoolYear=' + this.data.beginSchoolYear + '&endSchoolYear=' + this.data.endSchoolYear + '&classId=' + this.data.classId
          })
        }

      }

    }
  },
  radioChange: function (e) {
    if (!this.data.content) return
    this.setData({
      shows: !this.data.shows
    })
  },

  changeAutoplay() {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },

  intervalChange(e) {
    this.setData({
      interval: e.detail.value
    })
  },

  durationChange(e) {
    this.setData({
      duration: e.detail.value
    })
  }

})